package com.harmonk.firstscene.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import androidx.room.Delete
import androidx.room.OnConflictStrategy
import com.harmonk.firstscene.db.entity.Vehicle
import kotlinx.coroutines.flow.Flow

@Dao
interface VehicleDao {
    @Query("SELECT * FROM vehicles WHERE vehicleId = :id")
    suspend fun getVehicleById(id: Long): Vehicle?

    @Query("SELECT * FROM vehicles WHERE eventId = :eventId")
    fun getVehiclesByEventId(eventId: Long): Flow<List<Vehicle>>

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun insertVehicle(vehicle: Vehicle): Long

    @Update
    suspend fun updateVehicle(vehicle: Vehicle)

    @Delete
    suspend fun deleteVehicle(vehicle: Vehicle)
    
    @Query("DELETE FROM vehicles WHERE eventId = :eventId")
    suspend fun deleteVehiclesByEventId(eventId: Long): Int
}